import 'package:flutter/material.dart';
import 'package:lai_zhan/widget/GSYTabBarWidget.dart';
import 'package:lai_zhan/common/style/AppStyle.dart';
import 'package:lai_zhan/page/tab/HomeTab.dart';
import 'package:lai_zhan/page/tab/ClassTab.dart';
import 'package:lai_zhan/page/tab/MineTab.dart';

class IndexPage extends StatelessWidget {

  static final String rName = "index";

  /// 单击提示退出
  Future<bool> _dialogExitApp(BuildContext context) {
    return showDialog(
        context: context,
        builder: (context) => new AlertDialog(
          content: new Text('是否退出莱战健生'),
          actions: <Widget>[
            new FlatButton(
                onPressed: () => Navigator.of(context).pop(false),
                child: new Text('取消')),
            new FlatButton(
                onPressed: () {
                  Navigator.of(context).pop(true);
                },
                child: new Text('退出'))
          ],
        ));
  }

  _renderTab(icon, text) {
    return new Tab(
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[new Icon(icon, size: 25.0), new Text(text)],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    List<Widget> tabs = [
      _renderTab(AppIcon.MUSCLE_MAN,'主页'),
      _renderTab(AppIcon.CLASS_LIST,'课程'),
      _renderTab(AppIcon.MINE,'个人'),
    ];

    return WillPopScope(
      onWillPop: () {
        return _dialogExitApp(context);
      },
      child: new GSYTabBarWidget(
        type: GSYTabBarWidget.BOTTOM_TAB,
        tabItems: tabs,
        tabViews: [
          new HomeTab(),
          new ClassTab(),
          new MineTab(),
        ],
        backgroundColor: Color(AppColors.cyan),
        indicatorColor: Color(AppColors.cyan),
        labelColor: Color(AppColors.cyan),
      ),
    );;
  }
}
